package com.jiyun.courselist.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.courselist.mapper.CourseMapper;
import com.jiyun.courselist.service.CourseService;
import com.jiyun.model.Course;
import com.jiyun.vo.CourseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    @Autowired
    CourseMapper courseMapper;



    @Override
    public Page<CourseVo> findPage(Integer pageNum, Integer pageSize, CourseVo courseVo) {
        Page<CourseVo> courseVoPage = new Page<>(pageNum, pageSize);
        courseMapper.findPage(courseVoPage,courseVo);
        return courseVoPage;
    }

    @Override
    public List<Course> courseList() {
//        统计课程信息
        ArrayList<Course> list1 = new ArrayList<>();
        LambdaQueryWrapper<Course> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(Course::getGood);
        List<Course> list = courseMapper.selectList(lambdaQueryWrapper);
        list1.clear();
        for (int i = 0; i < 1; i++) {
            list1.add(list.get(i));
        }
        return list1;
    }

    @Override
    public Integer totleti(Integer id) {
       return courseMapper.totleti(id);
    }

    @Override
    public Integer finalti(Integer id) {
        return courseMapper.finalti(id);
    }
}
